package com.itheima.advantagesup.controller;


import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.vo.RolesPageBeanVO;
import com.itheima.advantagesup.service.SysRoleService;
import com.itheima.advantagesup.vo.RoleVO;
import com.itheima.advantagesup.vo.RoleVO2;
import com.itheima.advantagesup.vo.RoleVO3;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sys_role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/list")
    public R list(Integer page , Integer limit, String name){
        log.info("分页查询:{}",page,limit,name);
        RolesPageBeanVO rolesPageBeanVO = sysRoleService.list(page,limit,name);
        return R.success(rolesPageBeanVO);
    }

    @GetMapping("/allData")
    public R allData(){
        log.info("获取全部数据");
        List<RoleVO> roleVOs = sysRoleService.allData();
        return R.success(roleVOs);
    }

    @PostMapping("/add")
    public R add(@RequestBody RoleVO2 roleVO2){
        log.info("添加角色:{}",roleVO2);
        sysRoleService.add(roleVO2);
        return R.success();
    }

    @GetMapping("/del")
    public R delete(String id){
        log.info("根据id删除角色:{}",id);
        sysRoleService.delete(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R getInfo(String id){
        log.info("根据id获得角色:{}",id);
        RoleVO3  roleVO3 = sysRoleService.getInfo(id);
        return R.success(roleVO3);
    }

    @PostMapping("/update")
    public R update(@RequestBody RoleVO3 r){
        log.info("修改角色:{}",r);
        sysRoleService.update(r);
        return R.success();
    }

}
